<?php

class Parser
{
	private $_extra;
	
	public function Parser($extra = false)
	{
		$this->_extra = $extra;
	}
	
	public function bb2html($text)
	{
		if($this->_extra)
		{
			$search = "/\[intro\](.*?)\[\/intro\]\n(.*?)/";
			$replace = "<div class=\"introduction\">$1</div><div class=\"news\">$2</div>";
			$text = preg_replace($search, $replace, $text);
		}
		else
		{
			$search = "/\[intro\](.*?)\[\/intro\]\n/";
			$matched = preg_match($search, $text, $matches);
			if($matched)
			{
				$text = $matches[1];
			}
		}
		
		$text = preg_replace("/\[b\](.*?)\[\/b\]/", "<b>$1</b>", $text);
		$text = preg_replace("/\[i\](.*?)\[\/i\]/", "<i>$1</i>", $text);
		$text = preg_replace("/\[u\](.*?)\[\/u\]/", "<u>$1</u>", $text);
		
		$text = nl2br($text);
		
		return $text;
	}
}

?>